﻿/*  
 * Helix Engine
 * http://helixengine.codeplex.com/
 * 
 * Copyright (c) 2010 - 2011 Joe Hegarty
 *  
 * This source code is subject to the terms of the Microsoft Public License (Ms-PL). 
 *  
 * Redistribution and use in source and binary forms, with or without modification, 
 * is permitted provided that redistributions of the source code retain the above 
 * copyright notices and this file header. 
 * 
 * For details please see http://www.opensource.org/licenses/ms-pl.html 
 *  
 * All other rights reserved. 
 *
 */  


using System;
using System.Windows.Controls;

using HelixEngine.Maths;

namespace HelixEngine.Render
{
    /// <remarks>
    /// Represents the rendering subsystem of the engine
    /// </remarks>
    public sealed class RenderManager
    {
        uint _nextSceneId = 1;
        SceneManager _rootScene;

        /// <summary>
        /// 
        /// </summary>
        public SceneManager RootScene
        {
            get
            {
                return _rootScene;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sceneRoot"></param>
        public RenderManager(Image sceneRoot)
        {
            _rootScene = CreateScene("RootScene", (int) sceneRoot.Width, (int) sceneRoot.Height);
            sceneRoot.Source = _rootScene.RenderTarget;
        }

        /// <summary>
        /// Creates a scene to target for rendering
        /// </summary>
        /// <param name="name">A friendly name to give the scene</param>
        /// <param name="pixelWidth">The desired width of the scene in pixels</param>
        /// <param name="pixelHeight">The desired height of the scene in pixels</param>
        /// <returns>A scene manager representing the created scene</returns>
        public SceneManager CreateScene(string name, int pixelWidth, int pixelHeight)
        {
            SceneManager manager = new SceneManager(_nextSceneId, name, pixelWidth, pixelHeight);

            ++_nextSceneId;

            return manager;
        }

        /// <summary>
        /// Creates a scene to target for rendering
        /// </summary>
        /// <param name="name">A friendly name to give the scene</param>
        /// <returns>A scene manager representing the created scene</returns>
        public SceneManager CreateScene(string name)
        {
            return CreateScene(name, IsometricSettings.GameWidth, IsometricSettings.GameHeight);
        }
    }
}
